<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="ls" uri="/ls-trade-tags"%>
<%@ include file="/common/taglibs.jsp"%>

<html>
<head>
<%@ include file="/common/meta.jsp"%>
<%@ include file="/common/css_js.jsp"%>
		
	<script type="text/javascript">
		var iframeResize = function(){
			var targObj = self;
			//1.  取得iframe的对象
			var targWin = targObj.parent.document.getElementById("orderTemplateItemIframe");
			//2.  取得本页面的显示数据对象
			var projectionTypeTable = document.getElementById("orderTemplateItemDiv");
			
			if(targWin != null) {
			
				//3, 下面是取数据表格高度,
				// 也可取本htm文档的高度 ： var HeightValue = targObj.document.body.scrollHeight
				var HeightValue = projectionTypeTable.scrollHeight+40;
				targWin.style.height = HeightValue + "px";
			}
			
		}
		
		$(document).ready(function() {
			$("#mainForm").validate();
			iframeResize();
			parent.ajaxGetTotalPrice();
		});	
	
		function clickBtn(action,id,e){
			switch(action){
			case "add":
				parent.popup(e, "order-template-item!add.action?no-decorate&orderTemplateId="+"<s:property value='orderTemplateId'/>", "width:700;height:600;");
				return;	
	
			case "saveNumber":
				$("#mainForm").attr("action","order-template-item!saveNumber.action?no-decorate");
				break;
	
			case "delete":
				window.location="order-template-item!delete.action?no-decorate&orderTemplateId=<s:property value='orderTemplateId'/>&orderTemplateItem.id="+id;
				return;	
	
			case "batchDelete":
				$("#mainForm").attr("action","order-template-item!batchDelete.action?no-decorate");
				break;
				
			case "edit":
				parent.popup(e, "order-template-item!edit.action?no-decorate&monitorTransmission.id="+id+"&orderTemplateId="+"<s:property value='orderTemplateId'/>", "width:600;height:300;");
				return;		
				
			case "back":
				window.location="customer.action";
				return;			
				
			case "install":
				window.location="monitor.action?monitorTransmission.id="+id;
				return;				
			}
			
			$("#mainForm").submit();
		}	
	
	</script>
</head>

<body style="background-color: transparent;">
	
 	<s:form name="mainForm" id="mainForm"
		action="order-template-item!batchDelete.action?no-decorate" method="post">
		<s:hidden name="orderTemplateId" id="orderTemplateId"></s:hidden>

		<div class="sListBorder" id="orderTemplateItemDiv">
		
			<div class="sList">
				<table cellspacing="0" cellpadding="0" border="0" width="100%"
					class="sTable">
					<tbody>
						<tr>
							<td class="sTh checkbox"><input type="checkbox" name=""
								id="controlCheckbox" class="inputCheckbox"
								onclick="clickParent('controlCheckbox','ids')" />
							</td>
							<td class="sTh t">类型</td>
							<td class="sTh t">产品名</td>
							<td class="sTh t" style="width:200px">单价</td>
							<td class="sTh t" style="width:200px">数量</td>
							<td class="sTh t">合计</td>
							<td class="sTh t">&nbsp;</td>
						</tr>

						<s:if test="%{results!=null&&results.size()!=0}">
						
							<s:iterator value="results" var="orderTemplateItem" status="st">

								<s:set var="trClass" value="'sRow1'"></s:set>
								<s:if test="#st.index%2==0">
									<s:set var="trClass" value="'sRow2'"></s:set>
									<s:else>
										<s:set var="trClass" value="'sRow1'"></s:set>
									</s:else>
								</s:if>

								<tr class="<s:property value="#trClass"/>">
								
									<td class="sCell">
										<input type="checkbox" name="ids" value="<s:property value='#orderTemplateItem.id'/>" 
										       onclick="clickChild('controlCheckbox','ids')" class="inputCheckbox" />
								    </td>
									<td class="sCell"><ls:code2label type="PRODUCT_TYPE" code="#orderTemplateItem.product.type"/></td>
									<td class="sCell"><s:property value="#orderTemplateItem.product.name" /></td>
									<td class="sCell">
										<input type="text" class="inputText required number" style="width:180px" name="results[<s:property value='#st.index' />].price" value="<s:property value='#orderTemplateItem.price' />"/>
									</td>
									
									<td class="sCell">
										<input type="text" class="inputText required number" style="width:180px" name="results[<s:property value='#st.index' />].number" value="<s:property value='#orderTemplateItem.number' />"/>
										<input type="hidden"" name="results[<s:property value='#st.index' />].id"  value="<s:property value='#orderTemplateItem.id' />"/>
										<input type="hidden"" name="results[<s:property value='#st.index' />].version"  value="<s:property value='#orderTemplateItem.version' />"/>
									</td>
									
									<td class="sCell"><s:property value="%{#orderTemplateItem.number*#orderTemplateItem.price}"/></td>
									<td class="sCell buttonCell"><div class="button sbtn">
											<div class="left">
												<div class="right">
													<input type="button"
														onclick="clickBtn('delete','<s:property value='#orderTemplateItem.id'/>',event)"
														value="删除" name="" id="" class="inputButton" />
												</div>
											</div>
										</div>
								     </td>
								</tr>

							</s:iterator>
						</s:if>
					</tbody>
				</table>
			</div>

			<div class="btnSet btnSetTypeA">
				<div class="left">
					<div class="button">
						<div class="left">
							<div class="right">
								<input type="button" onclick="clickBtn('saveNumber','',event)"
									value="批量保存" name="" id="" class="inputButton">
							</div>
						</div>
					</div>				
					<div class="button">
						<div class="left">
							<div class="right">
								<input type="button" onclick="clickBtn('add','',event)"
									value="批量添加" name="" id="" class="inputButton">
							</div>
						</div>
					</div>
					<div class="button">
						<div class="left">
							<div class="right">
								<input type="button" onclick="clickBtn('batchDelete','',event)" value="批量删除" name="" id="" class="inputButton">
							</div>
						</div>
					</div>
				</div>
			</div>

		</div>
	</s:form>
</body>
</html>